﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Customer.Bussiness_Service;
using Entity;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using ServiceCore;

namespace Customer.Areas.rk_question.Controllers
{

    [ApiController, Area("rk_question"), Route("/question/[action]")]
    public class androidController : ControllerBase
    {
        private readonly Iquestion_service _service;
        private readonly IToole_DI _tool;
        public androidController(Iquestion_service service, IToole_DI tool)
        {
            _service = service;
            _tool = tool;
        }

        /// <summary>
        ///  检测机器是否指定了策略
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpGet]
        public ResultObjModel check_mch_jurisdiction(string mchid)
        {
            var result = _service.check_mch_jurisdiction(mchid);
            return result;
        }

         
        /// <summary>
        ///  获取指定机器购物详情
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpGet]
        public ResultObjModel get_product_list(string mchid)
        {
            var result = _service.get_product_list(mchid);
            return result;
        } 
        /// <summary>
        ///  登录验证
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpGet]
        public ResultObjModel auth_login(string mchid, string worknum, string pwd)
        {
            var result = _service.auth_login(mchid, worknum, pwd);
            _tool.di_es.Add_Log($"auth_login==>{mchid}机器{worknum}登录=>{Newtonsoft.Json.JsonConvert.SerializeObject(result)}", "question_android");
            return result;
        }
        /// <summary>
        ///  设置新密码
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpGet]
        public ResultObjModel set_new_pwd(string mchid, string question_uid, string new_pwd)
        {
            var result = _service.set_new_pwd(mchid, question_uid, new_pwd);
            _tool.di_es.Add_Log($"set_new_pwd==>{mchid}机器{question_uid}设置新密码=>{Newtonsoft.Json.JsonConvert.SerializeObject(result)}", "question_android");
            return result;
        } 
        /// <summary>
        ///  根据策略返回答题列表
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpGet]
        public ResultObjModel get_question(string strategy_id)
        {
            var result = _service.get_question(strategy_id);
            return result;
        }

        /// <summary>
        ///  开始答题
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpPost]
        public ResultObjModel submit_answer(submit_answer model)
        {
            var result = _service.submit_answer(model);
            _tool.di_es.Add_Log($"submit_answer==>提交答题{Newtonsoft.Json.JsonConvert.SerializeObject(model)}=>{Newtonsoft.Json.JsonConvert.SerializeObject(new { result.data, result.code, result.msg })}", "question_android");
            return result;
        }

        /// <summary>
        ///  确认答题出货
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpGet]
        public ResultObjModel confirm_question_order(string order_id, bool? is_end, string out_params)
        {
            var result = _service.confirm_question_order(order_id, is_end, out_params);
            _tool.di_es.Add_Log($"confirm_question_order==>确认答题出货{Newtonsoft.Json.JsonConvert.SerializeObject(new { order_id, is_end, out_params })}=>{Newtonsoft.Json.JsonConvert.SerializeObject(result)}", "question_android");
            return result;
        }
    }
}